package com.idanchuang.component.sequence.id;

import com.idanchuang.component.sequence.id.config.SequenceConfigBean;
import com.idanchuang.component.sequence.id.service.GeneralSeqIdService;
import com.idanchuang.component.sequence.id.service.GeneralSeqIdServiceImpl;
import com.idanchuang.sequence.service.api.client.ISequenceFeignClient;
import com.idanchuang.sun.core.Subscribe;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yjy
 * @date 2020/3/31 16:33
 **/
@Configuration
@Subscribe("sequence-service")
@EnableFeignClients("com.idanchuang.sequence.service.api.client")
public class ComponentSequenceIdAutoConfiguration {

    @Bean
    @ConfigurationProperties("idanchuang.component.sequence.id")
    public SequenceConfigBean sequenceConfigBean() {
        return new SequenceConfigBean();
    }

    @Bean
    @ConditionalOnMissingBean(GeneralSeqIdService.class)
    public GeneralSeqIdService idUtil(ISequenceFeignClient iSequenceFeignClient, SequenceConfigBean sequenceConfigBean) {
        return new GeneralSeqIdServiceImpl(iSequenceFeignClient, sequenceConfigBean);
    }

}
